<?php

namespace mpend\modules\activity\models;

use Yii;

/**
 * 班组记工本按日期统计模型
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class ActivitySearch extends \common\models\activity\Activity {

    /**
     * @inheritdoc
     */
    public function buildQuery($alias = 't') {
        $query = static::find();
        if ($alias) {
            $query->alias($alias);
            $alias .= '.';
        }
        $query->active(static::STATUS_ACTIVE);
        $query->andWhere([
            't.type' => static::TYPE_ENROLL,
        ]);
        $query->orderBy([
            $alias . 'recommend_at' => SORT_DESC,
            $alias . 'end_time' => SORT_DESC,
            $alias . 'begin_time' => SORT_DESC,
        ]);
        $query->debug();
        return $query;
    }

    /**
     * @inheritdoc
     */
    public function fields() {
        return [
            'id',
            'title' => 'name',
            'description',
            'begintime' => function() {
                return date('Y-m-d', $this->begin_time);
            },
            'endtime' => function() {
                return date('Y-m-d', $this->end_time);
            },
            'format',
            'medias',
            'thumb',
            'template',
            'canEnroll',
            'mplink',
        ];
    }

}
